﻿using System.Diagnostics;

namespace System.Management.HyperV
{
    /// <summary>
    /// Failure or Error information resulting from WMI operations targeting Hyper-V.
    /// </summary>
    public class HyperVException : ApplicationException
    {
        private Job sourceJob = null; // not always initialized; only when exception is the result of an action returning a Job object.

        #region Constructors
        public HyperVException()
            : base()
        {
        }

        public HyperVException(string message)
            : base(message)
        {
        }

        public HyperVException(string message, Exception innerException)
            : base(message, innerException)
        {
        }

        public HyperVException(Job sourceJob)
            : base((string)sourceJob.RawJob.Properties["ErrorDescription"].Value)
        {
            this.sourceJob = sourceJob;

            Debug.WriteLine(string.Empty.PadRight(50, '-'));
            Debug.WriteLine(">>> EXCEPTION <<<");
            Debug.WriteLine(string.Empty.PadRight(50, '-'));
            Debug.WriteLine(sourceJob.RawJob.GetText(TextFormat.Mof));
            Debug.WriteLine(string.Empty.PadRight(50, '-'));
        }
        #endregion
    }
}
